package com.pashanhoo.zookeeper;


import org.apache.zookeeper.*;

import java.util.concurrent.CountDownLatch;

/**
 * @author 胡庆安
 * @version V1.0
 * @Package com.pashanhoo.zookeeper
 * @date 2020/12/17 15:44
 * @Copyright © 2010-2021 爬山虎科技（扬州）有限公司
 */
public class Test {
    public static void main(String[] args) throws  Exception{
        CountDownLatch countDownLatch = new CountDownLatch(1);

        ZooKeeper zookeeper = new ZooKeeper("192.168.88.187:2181", 5000, (WatchedEvent x) -> {
            if (x.getState() == Watcher.Event.KeeperState.SyncConnected) {
                System.out.println("连接成功");
                countDownLatch.countDown();
            }
        });
        countDownLatch.await();
        System.out.println(zookeeper.getSessionId());
        zookeeper.close();
    }

    // 枚举的方式
    public static void createTest1(ZooKeeper zookeeper) throws Exception{
        String str = "node";
        String s = zookeeper.create("/node", str.getBytes(),
                ZooDefs.Ids.READ_ACL_UNSAFE, CreateMode.PERSISTENT);
        System.out.println(s);
    }

}
